package net.qiqb.execute;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.executing.annotation.Command;
import net.qiqb.core.executing.annotation.HandleBusiness;
import net.qiqb.core.executing.annotation.ObtainAggregateObject;
import net.qiqb.core.executing.annotation.PersistAggregateObject;

@Slf4j
@Command(UserEmail.class)
public class CreateUserExtraEmailCmd {

    private final String email;

    public CreateUserExtraEmailCmd(String email) {
        this.email = email;
    }

    /**
     * 加载器
     *
     * @return
     */
    @ObtainAggregateObject
    public UserEmail obtainUserEmail() {
        final UserEmail userEmail = new UserEmail(this.email);
        log.info("UserEmail创建:{}", userEmail.getEmail());
        return userEmail;
    }

    @HandleBusiness
    public void executeBusiness(UserEmail userEmail, User user) {
        log.info("UserEmail 执行器执行:{}", userEmail.getEmail());
    }

    @PersistAggregateObject
    public void persist(UserEmail newUser, UserEmail oldUser) {
        log.info("用户UserEmail聚合根持久话：" + newUser.getEmail());
    }
}
